import request from '@/utils/request';

/**
 * 查询菜单列表
 * @param params 查询条件
 */
export async function listMenus(params) {
  const res = await request.post('/auth/menu/all', params);
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加菜单
 * @param data 菜单信息
 */
export async function addMenu(data) {
  const res = await request.post('/auth/menu/save', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改菜单
 * @param data 菜单信息
 */
export async function updateMenu(data) {
  const res = await request.post('/auth/menu/update', data);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除菜单
 * @param id 菜单id
 */
export async function removeMenu(params) {
  const res = await request.post('/auth/menu/batchDelete', params);
  if (res.data.code === 2000) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
